pub trait DensityField:
Send
+ Sync
+ Any {
// Required methods
fn aabb(&self, info: &BodyAccessInfo) -> Aabb<Scalar>;
fn density_at_point(
&self,
point: Vec3<Scalar>,
info: &BodyAccessInfo,
) -> Scalar;
// Provided methods
fn density_at_region(
&self,
region: Aabb<Scalar>,
info: &BodyAccessInfo,
) -> DensityRange { ... }
fn normal_at_point(
&self,
point: Vec3<Scalar>,
resolution: Vec3<Scalar>,
info: &BodyAccessInfo,
) -> Vec3<Scalar> { ... }
}Required Methods§
Sourcefn aabb(&self, info: &BodyAccessInfo) -> Aabb<Scalar>
fn aabb(&self, info: &BodyAccessInfo) -> Aabb<Scalar>
Returns the AABB that contains the density field.
Sourcefn density_at_point(&self, point: Vec3<Scalar>, info: &BodyAccessInfo) -> Scalar
fn density_at_point(&self, point: Vec3<Scalar>, info: &BodyAccessInfo) -> Scalar
Returns the precise density at the given point. Reported densities are useful for narrow area queries.
Value 0.0 means no shape occupancy, 1.0 means full occupancy and values in between are considered density gradient. Shape might report scaled densities, e.g. reporting 0.5 on entire shape.
Scaled densities are useful to represent soft shapes like fluid or fog. This allows for collision queries to achieve partial penetration based on density threshold, so if we have an object that has hard body core and soft outline, another object might partially penetrate that object outline and still not report collision.
Provided Methods§
Sourcefn density_at_region(
&self,
region: Aabb<Scalar>,
info: &BodyAccessInfo,
) -> DensityRange
fn density_at_region( &self, region: Aabb<Scalar>, info: &BodyAccessInfo, ) -> DensityRange
Returns the approximate minimum and maximum density at the given region. Reported densities are useful for broad area queries.
This is useful for queries that require density at a larger region, for example if some collision queries do quad/oct tree subdivision use min-max to tell if region should be subdivided further or not.
The default implementation divides the region into chunks and samples
densities at the center of each chunk using density_at_point and then
reduces the results to find the minimum and maximum density.
You should implement this method if you want to provide a more
efficient way to compute the density range at a specific region.
Sourcefn normal_at_point(
&self,
point: Vec3<Scalar>,
resolution: Vec3<Scalar>,
info: &BodyAccessInfo,
) -> Vec3<Scalar>
fn normal_at_point( &self, point: Vec3<Scalar>, resolution: Vec3<Scalar>, info: &BodyAccessInfo, ) -> Vec3<Scalar>
Returns normalized “surface” normal at the given point.
It represents the direction of the density change gradient from more dense to less dense change at that point. Resolution parameter is used in case when only way to calculate normal is by multisampling, so resolution can be used for sampling offsets around queried point.
The default implementation returns zero meaning no particular direction.