Skip to main content

Bvh

Struct Bvh 

Source
pub struct Bvh { /* private fields */ }
Expand description

Bounding Volume Hierarchy:基于 AABB 的二叉加速结构。

Implementations§

Source§

impl Bvh

Source

pub fn new() -> Self

构建空 BVH。

Source

pub fn build(mesh: &MeshStorage) -> Self

从网格构建 BVH(仅包含三角面)。

非三角面(n-gon)被跳过;退化三角形(含重复顶点)也跳过。

Source

pub fn ray_intersection( &self, origin: [f64; 3], direction: [f64; 3], mesh: &MeshStorage, ) -> Option<RayHit>

射线与网格求最近交点(BVH 加速)。

返回 t 最小的 RayHit;无交点返回 None。 复杂度平均 $O(\log F)$,最坏 $O(F)$。

Source

pub fn nearest_point( &self, p: [f64; 3], mesh: &MeshStorage, ) -> Option<(FaceId, [f64; 3], f64)>

最近点查询:在网格三角面上查找距离 p 最近的点。

返回 (face_id, closest_point, distance_squared);网格无三角面时返回 None

Source

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)做最终判定。

Source

pub fn ray_count_hits( &self, origin: [f64; 3], direction: [f64; 3], mesh: &MeshStorage, ) -> u32

射线与网格所有三角面交点数(用于射线奇偶法判定内外)。

Bvh::ray_intersection 不同,本方法不返回最近交点而是统计所有命中, 因为射线奇偶法需要交点总数的奇偶性。

Source

pub fn node_count(&self) -> usize

BVH 节点总数。

Source

pub fn is_empty(&self) -> bool

是否为空(无三角面)。

Source

pub fn leaf_count(&self) -> usize

叶子节点数。

Source

pub fn depth(&self) -> usize

最大树深(根节点深 1)。

Trait Implementations§

Source§

impl Clone for Bvh

Source§

fn clone(&self) -> Bvh

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Bvh

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Bvh

Source§

fn default() -> Self

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

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

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

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

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

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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.