pub struct Bvh { /* private fields */ }Expand description
Bounding Volume Hierarchy:基于 AABB 的二叉加速结构。
Implementations§
Source§impl Bvh
impl Bvh
Sourcepub fn build(mesh: &MeshStorage) -> Self
pub fn build(mesh: &MeshStorage) -> Self
从网格构建 BVH(仅包含三角面)。
非三角面(n-gon)被跳过;退化三角形(含重复顶点)也跳过。
Sourcepub fn ray_intersection(
&self,
origin: [f64; 3],
direction: [f64; 3],
mesh: &MeshStorage,
) -> Option<RayHit>
pub fn ray_intersection( &self, origin: [f64; 3], direction: [f64; 3], mesh: &MeshStorage, ) -> Option<RayHit>
射线与网格求最近交点(BVH 加速)。
返回 t 最小的 RayHit;无交点返回 None。
复杂度平均 $O(\log F)$,最坏 $O(F)$。
Sourcepub fn nearest_point(
&self,
p: [f64; 3],
mesh: &MeshStorage,
) -> Option<(FaceId, [f64; 3], f64)>
pub fn nearest_point( &self, p: [f64; 3], mesh: &MeshStorage, ) -> Option<(FaceId, [f64; 3], f64)>
最近点查询:在网格三角面上查找距离 p 最近的点。
返回 (face_id, closest_point, distance_squared);网格无三角面时返回 None。
Sourcepub fn faces_in_aabb(
&self,
query_aabb: &AABB,
mesh: &MeshStorage,
) -> Vec<FaceId>
pub fn faces_in_aabb( &self, query_aabb: &AABB, mesh: &MeshStorage, ) -> Vec<FaceId>
返回所有 AABB 与 query_aabb 相交的叶子节点中的面 ID。
用于布尔运算等需要“对一条边/一个三角形查找另一网格候选面“的场景, 把暴力 $O(F)$ 扫描降到平均 $O(\log F + k)$,$k$ 为候选面数。
注意:AABB 相交只是候选,调用方仍需用精确几何测试(如
segment_triangle_intersection)做最终判定。
Sourcepub fn ray_count_hits(
&self,
origin: [f64; 3],
direction: [f64; 3],
mesh: &MeshStorage,
) -> u32
pub fn ray_count_hits( &self, origin: [f64; 3], direction: [f64; 3], mesh: &MeshStorage, ) -> u32
射线与网格所有三角面交点数(用于射线奇偶法判定内外)。
与 Bvh::ray_intersection 不同,本方法不返回最近交点而是统计所有命中,
因为射线奇偶法需要交点总数的奇偶性。
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
BVH 节点总数。
Sourcepub fn leaf_count(&self) -> usize
pub fn leaf_count(&self) -> usize
叶子节点数。
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Bvh
impl RefUnwindSafe for Bvh
impl Send for Bvh
impl Sync for Bvh
impl Unpin for Bvh
impl UnsafeUnpin for Bvh
impl UnwindSafe for Bvh
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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 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>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§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).Source§unsafe fn to_subset_unchecked(&self) -> SS
unsafe 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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.